// 引入插件
import Vue from 'vue'
import Vuex from 'vuex'

// 引入接口
import { reqGetOrderList, reqCustomerAddress } from '@/api'
// 注册插件
Vue.use(Vuex)


// 定义方法
const state = {
    orderList: [],// 地址信息
    informationList: [] // 商品信息

}
const actions = {

    // 获取地址信息
    async GetAddressDate({ commit }, query) {
        const result = await reqCustomerAddress(query)
        if (result.code === 200) {
            commit('SaveAddress', result.data)
        } else {
            console.log(result.message);
        }
    },

    // 获取交易页信息
    async OrderInformation({ commit }, query) {
        const result = await reqGetOrderList(query)
        if (result.code === 200) {
            commit('TransactionInformation', result.data)
        } else {
            console.log(result.message);
        }
    },

}
const mutations = {
    // 保存数据
    SaveAddress(state, data) {
        // console.log(data);
        state.orderList = state.data
    },
    // 保存数据
    TransactionInformation(state, data) {
        console.log(data);

        state.informationList = data
    }

}
const getters = {
    // 商品列表
    detailArrayList(state) {
        return state.informationList.detailArrayList
    },
    // 实付金额
    originalTotalAmount(state) {
        return state.informationList.originalTotalAmount
    },
    // 总价格
    totalAmount(state) {
        return state.informationList.totalAmount
    },
    // 总数
    totalNum(state) {
        return state.informationList.totalNum
    },
    // 
    tradeNo(state) {
        return state.informationList.tradeNo
    }
}


export default {
    namespaced: true,
    state,
    actions,
    mutations,
    getters
}

